#include <iostream>
#include "evnetplus/http/http_server.h"
#include "evnetplus/event_loop_thread.h"

using namespace std;
using namespace evnetplus;

int main(int argc, char const *argv[])
{
    EventLoopThread::Ptr loopthread = EventLoopThread::Ptr(new EventLoopThread);
    loopthread->Start(true);

    http::Server::Ptr hs = make_shared<http::Server>(4);

    evnetplus::http::HTTPRequestCallback callback = [](
        EventLoop* loop,
        const http::ContextPtr& ctx,
        const http::HTTPSendResponseCallback& respcb)
    {
        respcb("hello this is evnetplus http server.");
    };
    hs->RegisterDefaultHandler(callback);

     evnetplus::http::HTTPRequestCallback callback1 = [](
        EventLoop* loop,
        const http::ContextPtr& ctx,
        const http::HTTPSendResponseCallback& respcb)
    {
        string body = ctx->body().ToString();

        cout << "/test request: " << body << endl;

        respcb("success");
    };
    hs->RegisterHandler("/test",callback1);

    hs->Init(9600);
    hs->Start();

    loopthread->Stop(true);

    return 0;
}
